unit Unit21;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, db, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  Buttons, StdCtrls, DBGrids, IBQuery, IBDatabase;

type

  { TForm21 }

  TForm21 = class(TForm)
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    Datasource1: TDatasource;
    DBGrid1: TDBGrid;
    Edit1: TEdit;
    ibq1: TIBQuery;
    ibt1: TIBTransaction;
    Label1: TLabel;
    Panel1: TPanel;
    Panel2: TPanel;
    procedure Edit1Change(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form21: TForm21;

implementation

{$R *.lfm}

{ TForm21 }

procedure TForm21.FormShow(Sender: TObject);
begin
  if ibt1.Active then ibt1.Commit;
  ibq1.SQL.Clear;
  ibq1.SQL.Add('select * from kontrahent');
  if trim(edit1.Text) <> '' then
  begin
    ibq1.SQL.Add('where (Upper(nazwaskr) like :a) or (Upper(nazwaskr) like :a)');
    ibq1.ParamByName('a').AsString:='%'+UpperCase(trim(edit1.Text))+'%';
  end;
  ibq1.SQL.Add('order by Upper(nazwaskr)');
  try
    ibt1.StartTransaction;
    ibq1.Open;
  except
    ibt1.Rollback;
  end;
end;

procedure TForm21.Edit1Change(Sender: TObject);
begin
  form21.FormShow(nil);
end;

end.

